<template>
	<view class="wrapp flex">
		<view class="wrapp-box">
			<u--input
			    border="surround"
			    v-model="value"
			  ></u--input>
			  <view style="margin-top: 40rpx;">
			  	<u-button type="primary" text="复制链接" shape="circle" @click="copre"></u-button>
			  </view>
			  <view class="txt">
			  	点击复制链接后在浏览器观看视频
			  </view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: 'http://www.qdlearn.cn/bolearn_online/user/login'
			};
		},
		methods: {
			copre() {
				let text = this.value
				// #ifdef H5
				let textarea = document.createElement("textarea")
				textarea.value = text 
				textarea.readOnly = "readOnly"
				document.body.appendChild(textarea)
				textarea.select() // 选中文本内容
				textarea.setSelectionRange(0, text.length) 
				uni.showToast({//提示
					title:'复制成功' ,
					icon:'success'
				})
				document.execCommand("copy") 
				textarea.remove()
				// #endif
				// #ifndef H5
				uni.setClipboardData({
				  data:text,//要被复制的内容
				  success:()=>{//复制成功的回调函数
					uni.showToast({//提示
					  title:`复制成功`,
					  icon:'success'
					})
				  }
				},true);
				// #endif

			},
		}
	}
</script>

<style lang="scss">
	.flex {
		display: flex;
		align-items: center;
		justify-content: center;
	}
.wrapp {
	padding: 20rpx;
	height: 100vh;
	&-box {
		width: 96%;
		.txt {
			margin-top: 30rpx;
			color: #999;
			font-size: 24rpx;
			text-align: center;
		}
	}
}
</style>
